package hot100.logos71To80;

/**
 * @author logos
 * date 2025/7/17 19:34
 * @version v1.0
 * @Package hot100.logos71To80
 */
public class logos79 {

    /**
     * 79. 跳跃游戏II
     * https://leetcode.cn/problems/jump-game-ii/?envType=study-plan-v2&envId=top-100-liked
     */

    class Solution {
        public int jump(int[] nums) {
            int n = nums.length;
            int next = 0;
            int cover = 0;
            int ans = 0;
            for (int i = 0; i < n - 1; i++) {
                next = Math.max(next, i + nums[i]);
                if (i == cover) {
                    cover = next;
                    ans++;
                }
            }
            return ans;
        }
    }
}
